package com.kun.interceptor;

import cn.hutool.core.util.RandomUtil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.MDC;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import java.util.Random;

/**
 * @className: LogInterceptor
 * @Description: 增加日志流水号
 * @author: kunkun
 * @date: 2025/7/26 18:26
 */
@Component
public class LogInterceptor  implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //增加日志流水号id
        MDC.put("LOG_ID",System.currentTimeMillis()+ RandomUtil.randomString(3));
        return true;
    }
}
